<!-- 折线图 -->
<style lang="stylus" scoped>
.pie
  height 100%
  background url('../../../assets/bg.jpg') no-repeat
  background-size 100% 100%
  .main
    width 100%
    height calc(100% - 100px)
    margin-top -15px
</style>

<template>
<div class="pie">
  <p style='font-family:微软雅黑;font-size:16px;color:#0B903C;font-weight:bold;line-height:50px;'>全市重点人群占比</p>
  <div class="main"></div>
</div>

</template>

<script>
import echarts from 'echarts'
import header from 'components/header/header'
import filter from 'components/filter/filter'
import axios from 'axios'
export default {
  data() {
    return {
      legendArr: [],
      color: this.$store.state.color,
      styleArr: [],
      myChart: {},
      name: ''
    }
  },
  methods: {
    _init() {
      this.myChart = echarts.init(document.querySelector('.pie .main'))
      var glo = this.GLOBAL.BASE_URL;
      this.myChart.on("click", function(params) {
        $(".table").show();
        if (params.name === "刑满释放人员") {
          $(".table iframe").attr("src", glo + "/a/anzhi/anzhiMain/vuelist").show();
        } else if (params.name === "吸毒人员") {
          $(".table iframe").attr("src", glo + "/a/jindu/jinduMain/vuelist").show();
        } else if (params.name === "社区矫正人员") {
          $(".table iframe").attr("src", glo + "/a/shejiao/shejiaoMain/vuelist").show();
        } else if (params.name === "特定利益群体") {
          $(".table iframe").attr("src", glo + "/a/weiwen/weiwenMain/vuelist").show();
        } else if (params.name === "严重精神障碍患者") {
          $(".table iframe").attr("src", glo + "/a/weiji/weijiMain/vuelist").show();
        } else if (params.name === "赴京省访重点人员") {
          $(".table iframe").attr("src", glo + "/a/xinfang/axinfangMain/vuelist").show();
        } else if (params.name === "在逃人员") {
          $(".table iframe").attr("src", glo + "/a/zaitao/zaitaoMain/vuelist").show();
        } else if (params.name === "邪教人员") {
          $(".table iframe").attr("src", glo + "/a/xiejiao/xiejiaoMain/vuelist").show();
        }
      })
      this.legendArr = this.myChart.getOption().series
      this.legendArr.forEach((data) => {
        data.selected = true;
      })
      this.$root.charts.push(this.myChart)
      window.addEventListener('resize', function() {
        this.myChart.resize()
      }.bind(this))
    }
  },
  components: {
    'v-header': header,
    'v-filter': filter
  },
  mounted() {
    // 基于准备好的dom，初始化echarts实例
    this.myChart = echarts.init(document.querySelector('.pie .main'))
    var areaname = localStorage.getItem('areaname');
    axios.get(this.GLOBAL.BASE_URL + '/a/sys/area/mapData?name=平顶山市').then((res) => {
    // axios.get('static/data/Data.json').then((res) => {
      if (res) {
        var arr;
        $(res.data).each(function() {
          if (this.name === "平顶山市") {
            arr = this.value.split(",");
          }
        })
        this.myChart.setOption({
          tooltip: {
            trigger: 'item',
            formatter: "{a} <br/>{b} : {c} ({d}%)"
          },
          series: [
            {
              name: '重点人群类型占比',
              type: 'pie',
              radius: '55%',
              data: [
                {value: arr[0], name: '刑满释放人员'},
                {value: arr[1], name: '吸毒人员'},
                {value: arr[2], name: '社区矫正人员'},
                {value: arr[3], name: '特定利益群体'},
                {value: arr[4], name: '严重精神障碍患者'},
                {value: arr[5], name: '赴京省访重点人员'},
                {value: arr[7], name: '在逃人员'},
                {value: arr[8], name: '邪教人员'}
              ],
              itemStyle: {
                emphasis: {
                  shadowBlur: 10,
                  shadowOffsetX: 0,
                  shadowColor: 'rgba(0, 0, 0, 1)'
                },
                normal: {
                  label: {
                    formatter(v) {
                      return v.name + " \n " + v.value + "人 (" + v.percent + "%)"
                    },
                    show: true,
                    fontWeight: 'bold'
                  }
                }
              },
              color: ['#0B903C', '#FFC300', '#C4F42D', '#CBCBCB']
            }
          ]
        });
        this._init()
      }
    });
  }
}

</script>
